package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.ExceptionLogMapper;
import com.itheima.pojo.ExceptionLog;
import com.itheima.pojo.SysLog;
import com.itheima.service.ExceptionLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Map;

/**
 * @ClassName ExceptionLogServiceImpl
 * @Description 系统异常 服务实现类
 * @Author pengkaka
 * @Date 2020/8/5 16:02
 * @Version 1.0
 **/
@Service
public class ExceptionLogServiceImpl implements ExceptionLogService {
    
    @Autowired
    private ExceptionLogMapper exceptionLogMapper;    
    
    // 分页获取系统异常列表
    @Override
    public Page<ExceptionLog> getPageList(Map<String, Object> searchMap) {
        Integer currentPage = (Integer) searchMap.get("currentPage");
        if (currentPage == null) {
            currentPage = 1;
        }
        Integer pageSize = (Integer) searchMap.get("pageSize");
        if (pageSize == null) {
            pageSize = 10;
        }

        PageHelper.startPage(currentPage, pageSize);

        Example example = new Example(ExceptionLog.class);
        Example.Criteria criteria = example.createCriteria();
        if (searchMap.get("keyword") != null && !"".equals(searchMap.get("keyword"))) {
            criteria.andLike("exception_message", "%" + searchMap.get("keyword") + "%");
        }
        if (searchMap.get("operation") != null && !"".equals(searchMap.get("operation"))) {
            criteria.andLike("operation", "%" + searchMap.get("operation") + "%");
        }
        if (searchMap.get("startTime") != null && !"".equals(searchMap.get("startTime"))) {
            String startTime = (String) searchMap.get("startTime");
            String[] time = startTime.split(",");
            if (time.length == 2) {
                criteria.andBetween("create_time",time[0],time[1]);
            }
        }
        criteria.andEqualTo("status","1");
        example.setOrderByClause("create_time desc");

        Page<ExceptionLog> pageList = (Page<ExceptionLog>) exceptionLogMapper.selectByExample(example);
        return pageList;
        
    }
}
